#include<stdio.h>
#include<stdlib.h>

#include <gtest\gtest.h>

char *m_strcat(char* src,char* str2);

int _tmain(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

char * m_strcat(char* src,char* str2){
    if(src==NULL&& str2 == NULL){
        return NULL;
    }
    if(src==NULL)return str2;
    if(str2 == NULL) return src;
    int len =0,len1=0;
    char * addr = src;
    char *addr1 = str2;
    while(*src++)++len;
    while(*str2++)++len1;
    char *temp = (char *)malloc(len+len1+1);
    char *p = temp;
    while(len>0 ){
        *temp++ = *addr++;
        len--;
    }
    while(len1>0 ){
        *temp++ = *addr1++;
        len1--;
    }
    *temp = '\0';
    return p;
}

TEST(testCase, test0)
{
    EXPECT_STREQ("abcdef", m_strcat("abc", "def"));
}

TEST(testCase, test1)
{
    EXPECT_STREQ("abc", m_strcat("abc", ""));
}

TEST(testCase, test2)
{
    EXPECT_STREQ("abc", m_strcat("abc", NULL));
}

TEST(testCase, test3)
{
    EXPECT_STREQ("abc", m_strcat(NULL, "abc"));
}

TEST(testCase, test4)
{
    EXPECT_STREQ(NULL, m_strcat(NULL, NULL));
}



